package cn.cstech.aijia.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with Android Studio.
 * Title:DesignerInfoList
 * Description:
 * Copyright:Copyright (c) 2014
 * Company:中国平安健康保险有限公司
 * Author:Alice
 * Date:15/9/2
 * Time:下午1:53
 * Version 1.0
 */
public class DesignerInfoList extends BaseDataHeader implements Serializable{
    private static final long serialVersionUID = 4181025325369068266L;

    public List<DesignerInfo> data;
    /**
     * 反序列化函数，用于从json字符串反序列化本类型实例
     */
    public static DesignerInfoList deserialize(String json) throws JSONException {
        if (json != null && !json.isEmpty()) {
            return deserialize(new JSONObject(json));
        }
        return null;
    }

    public static DesignerInfoList deserialize(JSONObject json) throws JSONException {
        if (json != null && json != JSONObject.NULL && json.length() > 0) {
            DesignerInfoList result = new DesignerInfoList();

            JSONArray valueArray = json.optJSONArray("value");
            if (valueArray != null) {
                int len = valueArray.length();
                result.data = new ArrayList<DesignerInfo>(len);
                for (int i = 0; i < len; i++) {
                    JSONObject jo = valueArray.optJSONObject(i);
                    if (jo != null && jo != JSONObject.NULL && jo.length() > 0) {
                        result.data.add(DesignerInfo.deserialize(jo));
                    }
                }
            }

            return result;
        }
        return null;
    }
}
